package com.me.regex;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.me.util.AppConstant;
import com.me.util.AppUtil;

public class AnalyseLocation {
	
	final static String PATTERN_KEYWORD = "(venue|location)[:\\s\n\n\b]+([^\n\r]+)";
	final static String LOCATION_PATTERN = "(rm\\s*[0-9]+|room\\s*[0-9]+|LG\\s*[0-9]+|LT[\\s-]?[A-Z])";
	final static String LANDMARK_PATTERN = "(Aberdeen|Ocean Park|Admiralty|Bank Of America Tower|Hutchison House|Lab Concept Queensway Plaza|Pacific Place|Causeway Bay|Fashion Walk|Caroline Centre|Causeway Bay Plaza 1|Causeway Bay Plaza 2|Circle Plaza|Circle Tower|Elizabeth House|Hang Lung Centre|Henry House|Hysan Place|Island Beverley|Jardine Center|Kyoto Plaza|Lee Theatre Plaza|Lhart|Macau Yat Yuen Centre|Midtown|Richmond Plaza|Sogo (Causeway Bay)|The Goldmark|Times Square|Windsor House|World Trade Center|Central|Central Pier No.7|City Hall|Entertainment Building|IFC|Jardine House|Man Yee Building|New World Tower|Prince's Building|The Forum|The Landmark|Chai Wan|New Jade Garden Shopping Arcade|Heng Fa Chuen|Paradise Mall|North Point|Island Place|Pok Fu Lam|Cyberport|Quarry Bay|TaiKoo Place|Sheung Wan|Grand Millennium Plaza|Infinitus Plaza|Sheung Wan Municipal Services Building And Civic Centre|Shun Tak Centre|The Pemberton|Western Market|Stanley|Murray House|Stanley Plaza|Tai Koo|Cityplaza|Kornhill Plaza|The Peak|Peak Galleria Shopping Centre|The Peak Tower|Wan Chai|Bowrington Road Market|CNT Tower|Causeway Centre (Brim 28)|Emperor Group Centre|Harbour Centre|Hong Kong Convention And Exhibition Centre|Hopewell Centre|Lockhart Road Municipal Services Building|QRE Plaza|Sun Hung Kai Center|Tai Yau Arcade|Wu Chung House|Diamond Hill|Plaza Hollywood|Ho Man Tin|Homantin Plaza|Hung Hom|Fisherman's Wharf|The Metropolis Mall|Wonderful Worlds of Whampoa|Jordan|London Plaza|Kowloon Bay|Amoy Plaza|Hong Kong International Trade & Exhibition Centre|MegaBox|Telford Plaza|Kowloon City|Kowloon City Plaza|Kowloon Tong|Festival Walk|Kwun Tong|apm Millennium City 5|Lai Chi Kok|Cheung Sha Wan Plaza|D2 Place|Lam Tin|Laguna City|Lok Fu|Lok Fu Shopping Centre|Mong Kok|Argyle Centre|Bank Centre|CTMA Centre|Chong Hing Square|Dundas Square|Gala Place|Ginza Plaza|Golden Era Plaza|Grand Plaza|Ho King Commercial Centre|Kelly Commercial Centre|King Wah Centre|Ladies' Market|Langham Place|Moko|Prince Edward|Pionner Centre|San Po Kong|New Tech Plaza|Sham Shui Po|Dragon Centre|Tai Kok Tsui|Olympian City 1|Olympian City 2|Olympian City 3|Tsim Sha Tsui|1881 Heritage|Carnarvon Plaza|China Hong Kong Centre|China Hong Kong City|Chungking Mansions|Elements|Gateway Arcade|Harbour City|Harbour Crystal Centre|Hong Kong Cultural Centre|Houston Centre|Hyatt Regency Hong Kong|ICC|K11|Miramar Shopping Centre|New World Centre|Ocean Terminal|One Peking|Silvercord Tower|South Seas Centre|Star Ferry Pier|Star House|The Mira Mall|The ONE|The Sun Arcade|Tsim Sha Tsui Centre|iSQUARE|Tsz Wan Shan|Tsz Wan Shan Shopping Centre|Wong Tai Sin|Lung Chung Mall|Wong Tai Sin Shopping Centre|Yau Ma Tei|Temple Street|Yau Tong|Domain|Fanling|Fanling Town Centre|Fo Tan|Plaza Ascot|Kwai Fong|Kwai Chung Plaza|Metroplaza|Ma On Shan|Ma On Shan Centre|Ma On Shan Plaza|Sunshine Bazaar|Sunshine City Plaza|Sha Tin|Citylink|New Town Plaza|Shatin Plaza|Sheung Shui|Landmark North|Metropolis Plaza|Tai Po|Tai Po Market Complex|Tai Po Mega Mall|Tai Po Plaza|Uptown Plaza|Tin Shui Wai|Fortune Kingswood (Former: Kingswood Ginza)|Kingswood Richly Plaza|Tseung Kwan O|East Point City|Metro City Plaza|Nan Fung Plaza|Park Central|PopCorn|the Lane|Tsing Yi|Maritime Square|Tsuen Wan|City Landmark|Citywalk|Discovery Park Shopping Centre|Emperor Plaza|Luk Yeung Galleria|Nan Fung Centre|Panda Place|Tsuen Wan Plaza|Tuen Mun|Hanford Plaza|Ocean Walk|Sun Tuen Mun Centre|The Trend Plaza|Tuen Mun Town Plaza|V City|Yuen Long|Yuen Long Plaza|Outlying Islands|Chek Lap Kok|Non-Restricted Area - HKIA Terminal 1|Non-Restricted Area - HKIA Terminal 2|Restricted Area - HKIA Terminal|Discovery Bay|D Deck|Lantau Island|Hong Kong Disneyland|Ngong Ping 360|Tung Chung|CityGate|Island Line|Sheung Wan  Station|Central Station|Admiralty  Station|Wan Chai  Station|Causeway Bay  Station|Tin Hau  Station|Fortress Hill  Station|North Point  Station|Quarry Bay  Station|Tai Koo  Station|Sai Wan Ho  Station|Shau Kei Wan  Station|Heng Fa Chuen  Station|Chai Wan Station|HKU Station|Kennedy Town Station|Sai Ying Pun Station|Kwun Tong Line|Yau Ma Tei  Station|Mong Kok  Station|Prince Edward  Station|Shek Kip Mei  Station|Kowloon Tong  Station|Lok Fu  Station|Wong Tai Sin  Station|Diamond Hill  Station|Choi Hung  Station|Kowloon Bay Station|Ngau Tau Kok  Station|Kwun Tong  Station|Lam Tin  Station|Yau Tong  Station|Tiu Keng Leng Station|Tsuen Wan Line|Tsim Sha Tsui  Station|Jordan  Station|Sham Shui Po  Station|Cheung Sha Wan  Station|Lai Chi Kok  Station|Mei Foo  Station|Lai King  Station|Kwai Fong  Station|Kwai Hing  Station|Tai Wo Hau  Station|Tsuen Wan Station|Tseung Kwan O Line|Tseung Kwan O  Station|Hang Hau  Station|Po Lam  Station|LOHAS Park Station|Tung Chung Line & Disneyland Resort Line|Hong Kong Station|Kowloon  Station|Olympic  Station|Tsing Yi Station|Tung Chung Station|Sunny Bay  Station|Disneyland Station|AsiaWorld-Expo Station|East Rail Line|Hung Hom  Station|Mong Kok East  Station|Tai Wai Station|Sha Tin  Station|Fo Tan  Station|Racecourse  Station|University  Station|Tai Po Market  Station|Tai Wo  Station|Fanling  Station|Sheung Shui  Station|Lok Ma Chau Station|Lo Wu  Station|Ma On Shan Line|Che Kung Temple  Station|Sha Tin Wai  Station|City One  Station|Shek Mun  Station|Tai Shui Hang  Station|Heng On  Station|Ma On Shan  Station|Wu Kai Sha  Station|West Rail Line|East Tsim Sha Tsui  Station|Austin  Station|Nam Cheong  Station|Tsuen Wan West  Station|Kam Sheung Road  Station|Yuen Long  Station|Long Ping  Station|Tin Shui Wai  Station|Siu Hong  Station|Tuen Mun Station|Airport Express|Airport  Station|Caritas Oswald Cheung International House|L'hotel Island South|Conrad|Island Shangri-La|JW Marriott Hotel|The Upper House|Best Western Hotel|Crowne Plaza Hong Kong Causeway Bay|Holiday Inn Express|Regal Hong Kong Hotel|Rosedale Hong Kong|The Excelsior|The Park Lane|The Vela Hong Kong Causeway Bay|Four Seasons Hotel|Hotel LKF by Rhombus|Mandarin Oriental|The Landmark Mandarin Oriental|Happy Valley|The Empire (Happy Valley) Hotel|Mid-Levels|Terrace Room|YMCA Garden View Hotel|City Garden Hotel|Harbour Grand Hong Kong|Harbour Plaza North Point|Ibis North Point Hotel Hong Kong|Newton Hotel|The South China Hotel|Le Meridien Cyberport|Repulse Bay|The Arcade|Holiday Inn Express Hong Kong Soho|Hotel De Edge by Rhombus|Ibis Hong Kong Central & Sheung Wan Hotel|EAST Hotel|Tin Hau|Empire Hotel Hong Kong - Causeway Bay|L'Hotel Causeway Bay Harbour View|Metro Park Hotel Causeway Bay Hong Kong|Cosmo Hotel|Cosmopolitan Hotel|Empire Hotel Hong Kong - Wan Chai|Grand Hyatt|Hotel Indigo Hong Kong Island|King's Hotel|Luk Kwok Hotel|Metropark Hotel Wan Chai Hong Kong|Novotel Century Hong Kong|OZO Wesley Hotel|Renaissance Harbour View Hotel|South Pacific Hotel|The Charterhouse Causeway Bay Hotel|The Fleming|The Harbourview|Wharney Guang Dong Hotel|Western District|Best Western Hotel Harbour View|Courtyard By Marriott|Island Pacific Hotel|Traders Hotel Hong Kong|Harbour Grand Kowloon|Harbour Plaza Metropolis|Harbourfornt Horizon|Harbourview Horizon|Hotel sáv|Eaton, Hong Kong|Largos Hotel|Madera Hotel|Nathan Hotel|Novotel Nathan Road Kowloon Hong Kong|Prudential Hotel|San Diego Hotel|Shamrock Hotel|Regal Oriental Hotel|Dorsett Kwun Tong Hong Kong|L'hotel elan|Newton Place Hotel|Langham Place Hotel|Metropark Hotel Kowloon|Royal Plaza Hotel|Stanford Hotel|Metropark Hotel Mongkok|Penta Hotel Kowloon|Rosedale Hotel Kowloon|Silka West Kowloon Hotel Hong Kong|To Kwa Wan|Harbour Plaza 8 Degrees|B P International|Best Western Grand Hotel|Gateway Hotel|Guangdong Hotel Hong Kong|Holiday Inn Golden Mile|Hotel ICON|Hotel Panorama by Rhombus|Hyatt Regency Tsim Sha Tsui|InterContinental Grand Stanford Hotel|InterContinental Hong Kong|Kowloon Shangri-La Hotel|Marco Polo Hong Kong Hotel|New World Millennium Hong Kong Hotel|Park Hotel Hong Kong|Prince Hotel|Ramada Hotel Kowloon|Regal Kowloon Hotel|Sheraton Hong Kong Hotel|Stanford Hillview Hotel|The Empire Hotel Kowloon - Tsim Sha Tsui|The Kimberley Hotel|The Kowloon Hotel|The Langham|The Luxe Manor|The Mira|The Peninsula|The Ritz-Carlton|The Royal Garden|The Royal Pacific Hotel|W Hotel|YMCA|Casa Hotel|Hotel Rainbow Hong Kong|The Cityview|Courtyard By Marriott Hong Kong Sha Tin Hotel|Hyatt Regency Hong Kong Shatin|Regal Riverside Hotel|Royal Park Hotel|Harbour Plaza Resort City|Crowne Plaza Hong Kong Kowloon East|Maxen Harbour Hotel|L'hotel Nina Et Convention Centre|Panda Hotel|Royal View Hotel|Hong Kong Gold Coast Hotel|Sun Kong Hotel|Hong Kong SkyCity Marriott Hotel|Regal Airport Hotel|Auberge Discovery Bay|Disney’s Hollywood Hotel|Hong Kong Disneyland Hotel|Mui Wo Hotel|Silvermine Beach Hotel|Novotel Citygate Hong Kong|Ap Lei Chau|Deep Water Bay|Lan Kwai Fong|Sai Wan Ho|Shau Kei Wan|Shek O|Soho|Tai Hang|Cheung Sha Wan|Choi Hung|Knutsford Terrace|Lei Yue Mun|Mei Foo|Ngau Tau Kwok|Shek Kip Mei|Kwai Chung|Lau Fau shan|Lo Wu|Lok Ma Chau|Ma Wan|Sai Kung|Sham Tseng|Tai Wai|Tai Wo|Cheung Chau|Lamma Island|Ping Chau|Po Toi Island|Tai O)";

	public static ArrayList<String> analyse(String input) {

		ArrayList<String> output = new ArrayList<String>();
				
		Pattern patternWithKeyword = Pattern.compile(PATTERN_KEYWORD, Pattern.CASE_INSENSITIVE);
		
		Matcher matcherWithKeyword = patternWithKeyword.matcher(input);
		
		while (matcherWithKeyword.find()) {
			output.add(matcherWithKeyword.group(2));
		}
		
		if (output.size() > 0) 				
			return output;					//return if keyword exists in the input string
		
		
		String[] tokens = input.split("\\b");

		ArrayList<String> words = AppUtil.App.dataService.searchLocations(tokens);
		
		if (words.size() > 0) {

			String titlePattern = Functions.buildPattern(words);
			
			Pattern pattern = Pattern.compile(titlePattern, Pattern.CASE_INSENSITIVE);
		
			Matcher matcher = pattern.matcher(input);
			
			while (matcher.find()) {			
				output.add(matcher.group());
			}
		}
		
		Pattern pattern = Pattern.compile(LANDMARK_PATTERN, Pattern.CASE_INSENSITIVE);
		
		Matcher matcher = pattern.matcher(input);
		
		if (matcher.find()) {			
			output.add(matcher.group());
		}

		
		if (output.size() == 0)
			output.add("");			//empty string
		
		return output;
	}
	
}
